<template>
	<view>
		<mescroll-uni :scroll-y="true" :down="downOption" @down="downCallback" :up="upOption" @up="upCallback">
			<view class="allowRefresh">
				<view class="newcontent">
					<block v-for="(newsItem, newsIndex) in newsList.data" :key="newsIndex">
						<view class="frist" @click="bindClick(newsItem)">
							<image :src="localurl+newsItem.picture" mode="widthFix"></image>
							<view :class="['newtitle','fontsize'+fontsizenub]">{{newsItem.title}}</view>
						</view>
					</block>
				</view>
				<view class="uni-tab-bar-loading">
					<view class="loading-more">{{newsList.loadingText}}</view>
				</view>
			</view>
		</mescroll-uni>
	</view>
</template>

<script>
	import {common} from '@/common/publish.js';
	import MescrollUni from "mescroll-uni";
	export default{
		data(){
			return{
				localurl:common.url,
				newsList:{
					data: [],
					offset: 0,
					limit: 10,
					loadingText: '加载中...'
				},
				upOption: {
					auto: false
				},
				downOption:{},
				navigateId:''
			}
		},
		components:{
			MescrollUni
		},
		onLoad(option){
			let navigateId = option.navigateId;
			this.navigateId = navigateId
			this.getList(mescroll,navigateId)
		},
		methods:{
			//刷新
			downCallback(mescroll){
				this.newsList.offset = 0;
				this.getList(mescroll,this.navigateId)
			},
			//加载
			upCallback(mescroll){
				if (this.newsList.loadingText == '加载中...') {
					return false;
				}
				this.getList(mescroll,this.navigateId);
			},
			//加载列表
			getList(mescroll,navigateId){
				uni.request({
					url: common.url + '/api/Frontiers/pagelist.json',
					data:{
						offset: this.newsList.offset,
						limit: 10,
						navigateId
					},
					success:res => {
						if (res.statusCode == 200) {
							if (this.newsList.offset == 0) {
								this.newsList.data = res.data.rows
							} else {
								res.data.rows.forEach((v) => {
									this.newsList.data.push(v);
								})
							}
							this.newsList.offset = parseInt(this.newsList.offset) + parseInt(res.data.limit);
							this.newsList.total = res.data.total;
							if (this.newsList.offset >= this.newsList.total) {
								this.newsList.loadingText = '没有更多数据了'
								mescroll.endSuccess(10,false)
							} else {
								this.newsList.loadingText = '下拉加载更多'
								mescroll.endSuccess(10,true)
							}
						}
					}
				})
			},
			//跳转
			bindClick(data){
				uni.navigateTo({
					url: '/pages/qysecond/qysecond?id=' + data.id + '&img=' + data.picture + '&title=' + data.title
				});
			}
		}
	}
</script>

<style lang="scss">
	@import '@/common/publish.scss';
	@include fontsizefn(".zbtt",32upx);
	@include fontsizefn(".newtitle",32upx);
	@include fontsizefn(".nubdata",26upx);
	.frist{
		width: 100%;
		margin-bottom: 20upx;
		background: #efeff4;
		view{
			padding: 30upx 28upx;
			line-height:40upx;
		}
	}
	image{
		width: 100%;
	}
</style>
